package spc.webos.queue;

import org.apache.log4j.Logger;

class BizThread implements Runnable {
	BizPoolOnMessage bizPoolOnMessage;
	Object obj;
	AccessTPool pool;
	AbstractReceiverThread thread;

	public BizThread(BizPoolOnMessage bizPoolOnMessage, Object obj,
			AccessTPool pool, AbstractReceiverThread thread) {
		this.bizPoolOnMessage = bizPoolOnMessage;
		this.obj = obj;
		this.pool = pool;
		this.thread = thread;
	}

	public void run() {
		Logger log = this.bizPoolOnMessage.log;
		String str = "";
		try {
			long start = System.currentTimeMillis();
			long qstart = (this.obj instanceof QueueMessage) ? ((QueueMessage) this.obj).createTm
					: 0L;
			str = "do("
					+ ((this.obj instanceof QueueMessage) ? new String(
							((QueueMessage) this.obj).correlationId) : "")
					+ ")";
			if (log.isDebugEnabled())
				log.debug(str + ") start...");
			this.bizPoolOnMessage.onMessage.onMessage(this.obj, this.pool,
					this.thread);
			long end = System.currentTimeMillis();
			log.info(str + ", bizcost:" + (end - start) + ", cost:"
					+ (end - qstart));
		} catch (Throwable t) {
			log.warn(str + " fail", t);
		} finally {
			this.bizPoolOnMessage.releaseThread();
		}
	}
}
